﻿Imports DTO
Imports System.Data.SqlClient

Public Class BoPhanDAO
    Public Shared Function LayDanhSachBoPhan() As DataTable
        Dim dt As New DataTable
        dt = CKetNoi.GetDataTableByStoreProc("LayDSBoPhan")
        Return dt
    End Function

    Public Shared Function LayDanhSachBoPhanCBX() As DataTable
        Dim dt As New DataTable
        dt = CKetNoi.GetData("select MaBoPhan, TenBoPhan from BoPhan")
        Return dt
    End Function

    Public Shared Function ThemBoPhan(BoPhanDTO As BoPhanDTO) As Integer
        Dim kq As Integer
        Dim sql As String = String.Format("insert into BoPhan(TenBoPhan, GhiChu, MaTrangThai) values(N'{0}', N'{1}', {2})", BoPhanDTO.TenBoPhan, BoPhanDTO.GhiChu, BoPhanDTO.MaTrangThai)
        kq = CKetNoi.ExecNonQuery(sql)
        Return kq
    End Function

    Public Shared Function CapNhapBoPhan(BoPhanDTO As BoPhanDTO) As Integer
        Dim kq As Integer
        Dim listVal As New List(Of SqlParameter)

        listVal.Add(New SqlParameter("@maBP", BoPhanDTO.MaBoPhan))
        listVal.Add(New SqlParameter("@tenBP", BoPhanDTO.TenBoPhan))
        listVal.Add(New SqlParameter("@ghiChu", BoPhanDTO.GhiChu))
        listVal.Add(New SqlParameter("@maTT", BoPhanDTO.MaTrangThai))
        kq = CKetNoi.ExecQueryStoreProc("CapNhapBoPhan", listVal)
        Return kq
    End Function

    Public Shared Function XoaBoPhan(BoPhanDTO As BoPhanDTO) As Integer
        Dim kq As Integer
        Dim listVal As New List(Of SqlParameter)

        listVal.Add(New SqlParameter("@maBP", BoPhanDTO.MaBoPhan))
        kq = CKetNoi.ExecQueryStoreProc("XoaBoPhan", listVal)
        Return kq
    End Function

End Class
